<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function deepClone(params) {
      function isObj(o) {
        return (typeof o === 'object' || typeof o === 'function') && o != null
      }

      if (!isObj(params)) {
        throw new Error('这不是个对象')
      }

      let newObj = Array.isArray(params) ? [...params] : {
        ...params
      };

      Reflect.ownKeys(newObj).forEach((key) => {
        newObj[key] = isObj(params[key]) ? deepClone(params[key]) : params[key];
      })

      return newObj
    }

    let obj = {
      a: [1, 2, 3],
      b: {
        c: 2,
        d: 3
      }
    }
    let newObj = deepClone(obj)
    newObj.b.c = 1
    console.log(obj.b.c) // 2
  </script>
</body>

</html>